package com.jin.flashsaled.config;


import org.springframework.amqp.core.*;

import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQ
{
    //允许将对象序列化
    @Bean
    public MessageConverter jsonMessageConverter() {
        return new Jackson2JsonMessageConverter();
    }


    //定义队列
    @Bean
    public Queue queue()
    {
        return new Queue("seckillQueue",true);//定义队列，持久化队列
    }
    //定义交换机
    @Bean
    public TopicExchange exchange()
    {
        return new TopicExchange("seckillExchange",true,false);//true交换机持久化,false,不会自动删除

    }

    //绑定交换机队列与路由key
    @Bean
    public Binding binding(Queue queue, TopicExchange exchange)
    {

        //绑定交换机和消息队列，以及路由key,"#.queue.#",这个路由key是通配符，#代表任意,*代表一个单词

        return BindingBuilder.bind(queue).to(exchange).with("#.queue.#");
    }


}


